import pickle

data = None


def get_data_by_pickle():
    global data
    if data is not None:
        return data
    file_path = "data/data.pkl"
    with open(file_path, "rb") as f:
        data = pickle.load(f)
    return data

def get_data_for_model():
    data = pickle.load(open('data/x.pkl', 'rb'))
    date_list = pickle.load(open('data/date_list.pkl', 'rb'))
    name_list = pickle.load(open('data/name_list.pkl', 'rb'))
    return {'data': data, 'date_list': date_list, 'name_list': name_list}

# if __name__ == '__main__':

#     file_path = "data/data.pkl"
#     with open(file_path, "rb") as f:
#         data = pickle.load(f)

#     print(type(data))   # <class 'dict'>
#     for key in data["2010-01-04"].keys():
#         print('key = {}'.format(key))

#     print(data["2010-01-04"])   # 输出的是一个交易日的数据
#     print(data["2010-01-04"].close[0], data["2010-01-04"].index[0], len(data["2010-01-04"]))

#     # 股票 002558.XSHE, 603110.XSHG, 002611.XSHE在部分交易日存在空缺值，清注意处理

#     day_info = data["2010-01-04"]
#     #print(day_info.index)       # 输出各个股票的代码
